package com.ita.activemq;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Session;

import org.apache.activemq.command.ActiveMQQueue;

import com.ita.factory.MQConnFactory;

/**
 * Hello world!
 * 
 */
public class Consumer extends Thread {

	private static final String SEND_QUENE_NAME = "A2M_QUEUE";
	private static Destination queue;
	private static Session session;
	private MessageConsumer consumer;

	public Consumer() throws JMSException {
		queue = new ActiveMQQueue(SEND_QUENE_NAME);
		session = MQConnFactory.getConnection().createSession(false,
				Session.AUTO_ACKNOWLEDGE);
		consumer = session.createConsumer(queue);
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub

		try {
			consumer.setMessageListener(new BlockedListener());
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public void close() {

		try {
			session.close();
			consumer.close();
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
